<?php
/**
 * 
 * 价格查询模块
 * @author Jackie Yang
 *
 */
class model_price extends model_weixin{
	
	/**
	 * @description 获取有效的产品大类
	 * @author jackie yang
	 * @param  $data  array
	 */
	public static function get_price_class_list() {
		$data = array();
		$sql = "select product_class_id,class_name from weixin_product_class where status=0 and delete_flag=0 order by product_class_id asc";
		try {
    		$binds = array();
    		$st = self::DB()->dbh->prepare($sql);
    		$st->execute($binds);
    		$data = $st->fetchAll();
    	}catch(Exception $e){
            framework_static_function::write_log(__METHOD__.":".$e->getMessage(),'weixin_sql');
        }
        return $data;
	}
	/**
	 * 
	 * 获取某一大类的小类
	 * @param string $parent_id 产品父类ID
	 */
	public static function get_small_class_list($parent_id) {
		$data = array();
		$sql = "select product_id,produce_name from weixin_product where parent_id=:parent_id and status=0 and delete_flag=0 order by product_id asc";
		try {
    		$binds = array(':parent_id' => $parent_id);
    		$st = self::DB()->dbh->prepare($sql);
    		$st->execute($binds);
    		$data = $st->fetchAll();
    	}catch(Exception $e){
            framework_static_function::write_log(__METHOD__.":".$e->getMessage(),'weixin_sql');
        }
        return $data;
	}
	/**
	 * 获取产品材质信息
	 * @param string $produce_id 产品ID
	 */
	public static function get_marerials($produce_id){
		$data = array();
		if(empty($produce_id)){
			return $data;
		}
		$sql = "select `marerials`,`format` from `weixin_basic_price` where `produce_id` = :produce_id and `delete_flag` = 0";
		try {
    		$st = self::DB()->dbh->prepare($sql);
    		$st->execute(array(":produce_id" => $produce_id));
    		$data = $st->fetchAll();			
    	}catch(Exception $e){
    		framework_static_function::write_log($e->getMessage(),'weixin_sql');
    	}
		return $data;
	}
	/**
	 * 获取区域定价选项
	 * @param string $produce_id 产品ID
	 */
	public static function get_area_price($product_id){
		$data = array();
		if(empty($product_id)){
			return $data;
		}
		$sql = "select `area_price` from `weixin_product` where `product_id` = :product_id and `delete_flag` = 0";
		try {
    		$st = self::DB()->dbh->prepare($sql);
    		$st->execute(array(":product_id" => $product_id));
    		$data = $st->fetchColumn();
    	}catch(Exception $e){
    		framework_static_function::write_log($e->getMessage(),'weixin_sql');
    	}
		return $data;
	}
	/**
	 * 获取运送方式
	 * @param string $produce_id 产品ID
	 */
	public static function get_transport($product_id){
		$data = array();
		if(empty($product_id)){
			return $data;
		}
		$sql = "select `motor`,`shipping`,`motor_shipping`,`train` from `weixin_product` where `product_id` = :product_id and `delete_flag` = 0";
		try {
    		$st = self::DB()->dbh->prepare($sql);
    		$st->execute(array(":product_id" => $product_id));
    		$data = $st->fetch();
    	}catch(Exception $e){
    		framework_static_function::write_log($e->getMessage(),'weixin_sql');
    	}
		return $data;
	}
	/**
	 * 获取某一字段的值
	 * @param int $produce_id 产品ID
	 * @param string $filed 字段
	 */
	public static function get_filed($product_id,$filed){
		$data = array();
		if(empty($product_id)){
			return $data;
		}
		$sql = "select {$filed} from `weixin_product` where `product_id` = :product_id and `delete_flag` = 0";
		try {
    		$st = self::DB()->dbh->prepare($sql);
    		$st->execute(array(":product_id" => $product_id));
    		$data = $st->fetchColumn();
    	}catch(Exception $e){
    		framework_static_function::write_log($e->getMessage(),'weixin_sql');
		}
		return $data;
	}
	/**
	 * 获取价格字段列表
	 */
	public static function get_price_list() {
		$sql = "select `product_price_id`,`parent_id`,`price_name`,`depth` from `weixin_product_price`  where `delete_flag` = 0 order by product_price_id asc ";
		$result = array ();
		try {
			$st = self::DB ()->dbh->prepare ($sql);
			$st->execute ();
			$result = $st->fetchAll ();
		} catch ( Exception $e ) {
			framework_static_function::write_log ( $e->getMessage (), 'weixin_sql' );
			$result = array ();
		}
		return $result;
    }
    /**
     * 根据传入参数，查询出价格
     * @param array $params
     */
    public static function calc_total_price($params) {
    	$result = '';
    	////////////////////////逻辑还没有写完
    	return $result;
    }
}